package org.q.threads;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import org.q.StartMain;

public class MainThread {
	
	public static void main(String[] args) throws InterruptedException{
		System.setProperty("org.terracotta.quartz.skipUpdateCheck", "true");
		
		ExecutorService pool = Executors.newFixedThreadPool(2);
		for(int i=0;i<2;i++) {
			try {
				pool.execute((new MainThread2()));
			} catch (Exception e) {
				System.out.println("----------"+e.getMessage());
			}
		}
	}
	
	public void proc() throws InterruptedException {
		System.setProperty("org.terracotta.quartz.skipUpdateCheck", "true");
		
		ExecutorService pool = Executors.newFixedThreadPool(2);
		List<Thread> threads = new ArrayList<Thread>();
		for(int i=0;i<2;i++) {
			Thread t = new MainThread2();
			threads.add(t);
			try {
				pool.execute(t);
			} catch (Exception e) {
				System.out.println("----------"+e.getMessage());
			}
		}
		pool.shutdown();
		pool.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
		System.out.println("MainThread子线程执行结束，关闭线程池");
		while(StartMain.SHUTDOWN) {
			for(Thread t : threads) {
				if(t.isInterrupted()) {
					t.interrupt();
					t.join();
				}
			}
			System.out.println("正常结束程序");
			System.exit(1);
		}
	}

}
